package com.cwj;

@SuppressWarnings("all")
public class SlideWindow {

    /**
     * [l,r],滑动窗口最好选这个,r往右走一步,左边跟进
     */
    public int solution(String s) {
        int l = 0, r = 0;
        int size = s.length();
        int[] cur = new int[26];
        int ans = size;
        while (r < size) {
            cur[s.charAt(r - 'a')]++;
            while (l <= r && check()) {
                ans = Math.min(size, r - l + 1);
                cur[s.charAt(l++) - 'a']--;
            }
            r++;
        }
        return ans;
    }

    public boolean check() {
        return true;
    }


    /**
     * [l,r),尽量不要选择这个，因为这边无法保证 l > r
     */
    public int solution2(String s) {
        int l = 0, r = 0;
        int size = s.length();
        int[] cur = new int[26];
        int ans = size;
        while (l < size) {
            while (r < size && !check()) {
                cur[s.charAt(r++) - 'a']++;
            }
            if (check()) {
                ans = Math.min(ans, r - l);
            }
            cur[s.charAt(l++) - 'a']--;
        }
        return ans;

    }


}
